{extend name="./view/base/admin.html" /}
{block name="body"}
<ul class="nav nav-tabs" role="tablist">
    <li class="nav-item" role="presentation"><a class="nav-link {$status==1?'active':''}"
            href="{:url('index',['status'=>1])}">已安装</a>
    </li>
    <li class="nav-item" role="presentation"><a class="nav-link {$status==0?'active':''}"
            href="{:url('index',['status'=>0])}">待安装{if $noinstall_num>0}<span
                class="badge badge-danger"><?=$noinstall_num?></span>{/if}</a>
    </li>
</ul>
<div class="tab-content">
    <div class="tab-pane active" role="tabpanel">
        <div class="table-responsive">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>名称</th>
                        <th>介绍</th>
                        <th>版本号</th>
                        <th>作者</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($list as $v):?>
                    <?php if($v['status']==$status):?>
                    <tr>
                        <td><?=$v['title']?></td>
                        <td><?=$v['description']?></td>
                        <td><?=$v['version']?></td>
                        <td><?=$v['author']?></td>
                        <td>
                            <?php if($status==0):?>
                            <button class="btn btn-xs btn-success install" data-name="{$v['name']}">安装</button>
                            <?php else:?>
                                <?php if(!empty($v['config_url'])):?>
                                <a class="btn btn-xs btn-info" href="{$v['config_url']}">配置</a>
                                <?php endif;?>
                            <button class="btn btn-xs btn-danger uninstall" data-name="{$v['name']}">卸载</button>
                            <?php endif;?>
                        </td>
                    </tr>
                    <?php endif;?>
                    <?php endforeach;?>
                </tbody>
            </table>
        </div><!-- END table-responsive-->
    </div>
</div>
{/block}
{block name="script"}
<script>
    //安装插件
    $('.install').on('click', function () {
        let name = $(this).data('name');
        $.confirm('确定要安装' + name + '插件吗?', function () {
            $.submit('install', { name: name })
        })
    })
    //卸载插件
    $('.uninstall').on('click', function () {
        let name = $(this).data('name');
        $.confirm('确定要卸载' + name + '插件吗?', function () {
            $.submit('uninstall', { name: name })
        })
    })
</script>
{/block}